#include "MainState.h"
#include "Application.h"
#include "Track.h"
#include "hgesprite.h"
#include "World.h"
#include "GeneticsEngine.h"
#include <time.h>

MainState::MainState()
{
	m_pTrack = new Track;
	m_pTrack->Init();

	m_pWorld = new World();
	m_pWorld->Initiate();

	m_pGeneticsEngine = new GeneticsEngine;
	m_pGeneticsEngine->Init(m_pTrack);
}
MainState::~MainState()
{
	if(m_pTrack)
	{
		delete m_pTrack;
		m_pTrack = NULL;
	}
	if(m_pWorld)
	{
		delete m_pWorld;
		m_pWorld = NULL;
	}

	if(m_pGeneticsEngine)
	{
		delete m_pGeneticsEngine;
		m_pGeneticsEngine = NULL;
	}
}

void MainState::OnEnter()
{
}
void MainState::OnExit()
{
}
void MainState::OnPause()
{
}
void MainState::OnResume()
{
}

bool MainState::Update(float a_dt)
{
	m_pWorld->Update(a_dt);
	m_pGeneticsEngine->RunCycle(a_dt);

	 m_pGeneticsEngine->RunCycle(a_dt);
	return true;
}
void MainState::Render(float a_dt)
{
	HGE* pHGE = Application::GetInstance().GetHGE();

	pHGE->Gfx_BeginScene();
	pHGE->Gfx_Clear(0x00000000);

	if(m_pTrack)
		m_pTrack->RenderTrack();

	m_pWorld->Render(a_dt);

	pHGE->Gfx_EndScene();
}